<template>
    <div>
        <div class="content item-content">
            <div class="content-box item-content-box">
                <div class="content-item">
                    <div class="content-item-box">
                        <div class="post-title">
                            <a href="/index.php/main/forum/items" target="_blank">{{ item.title }}</a>
                            </div>
                        <div class="post-info">
                            <strong class="post-user">linkphp</strong>
                            <em class="post-time">2017-09-17</em>
                            <span class="post-tags"><a href="#" class="tags-info">mvc</a></span>
                            <span class="post-num"><i class="layui-icon">&#xe611;</i> 0</span>
                            </div>
                        </div>
                    <div class="content-item-box-dec">
                        <p>{{ item.content }}</p>
                        <strong class="post-last-time">最后一次编辑于: 2017-09-17</strong>
                        </div>
                    <!-- 回复开始 -->
                    <div class="content-item-box rep">
                        <div class="rep-item-box-img">
                            <img src="//q.qlogo.cn/qqapp/101235792/A645D3B0234D71AE1EB9B2366399817D/100">
                        </div>
                        <div>
                            <div class="post-title rep-title">
                                再做一遍没什么不好的，可以帮助你审查并规避前面做的不好的地方，
                                第二次做你会发现你能感受到更多不一样的东西
                            </div>
                            <div class="post-info">
                                <strong class="post-user">linkphp</strong>
                                <em class="post-time">2017-09-17</em>
                                <span class="post-num"><i class="layui-icon">&#xe611;</i> 1楼</span>
                            </div>
                        </div>
                    </div>
                    <!-- 回复结束 -->
                    <div class="content-item-box-repeat">
                        <div class="content-item-box-img">
                            <img src="//q.qlogo.cn/qqapp/101235792/A645D3B0234D71AE1EB9B2366399817D/100">
                            </div>
                        <div class="content-item-box-btn" v-if="isLogin === false">
                            <a class="layui-btn layui-btn-sm rep-btn" href="javascript:;" v-on:click="login">
                                未登入</a>
                        </div>
                        <div class="content-item-box-btn" v-else>
                            <a class="layui-btn layui-btn-sm rep-btn" href="javascript:;" v-on:click="rep">
                                <i class="layui-icon">&#xe642;</i> 回复</a>
                        </div>
                        <div class="content-item-box-notic">
                            <textarea id="notic" style="display: none;"></textarea>
                        </div>
                        </div>
                    </div>
                </div>
            </div>
    </div>
</template>

<script>
import request from '../link/request.js'
export default {
  name: 'Items',
  data () {
    return {
      item: {},
      contents: {},
      isLogin: false
    }
  },
  mounted () {
    let that = this
    that.isLogins()
    this.getThisData()
    layui.use('layedit', function () {
      let layedit = layui.layedit
      let index = layedit.build('notic', {
        height: 180
      })
      that.contents = index
      layedit.getContent(index)
    })
  },
  methods: {
    getThisData () {
      let that = this
      request.post('/index.php/main/forum/getItem', {
        id: this.$route.params.id
      })
        .then(function (response) {
          console.log(response)
          that.item = response
        })
    },
    toggle: function () {
    },
    rep () {
      let that = this
      layui.use('layedit', function () {
        let layedit = layui.layedit
        console.log(layedit.getContent(that.contents))
        request.post('/index.php/main/forum/reply', {
          id: that.$route.params.id,
          content: layedit.getContent(that.contents)
        })
          .then(function (response) {
            console.log(response)
          })
      })
    },
    isLogins () {
      let that = this
      request.get('/index.php/main/auth/isLogin')
        .then(function (response) {
          if (response.code === 2) {
            return false
          } else {
            that.isLogin = true
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    login () {}
  }
}
</script>

<style>
    @import url('../assets/css/forumItem.css');
</style>
